// Mine.cpp

#include "Mine.h"
#include <iostream>
/**
 * Constructor. Initialize it to empty.
 */
Mine::Mine()
{
	resetFlagsAndStates();
}

/**
 * Destructor.
 */
Mine::~Mine() { }

/**
* Sets the square as a mine or not.
*
* @param turnIntoMine if to turn the square into a mine or not
*/
void Mine::setAsMine( const bool turnIntoMine )
{
	isAMine = turnIntoMine;
}

/**
* Checks if the square is a mine.
*
* @return bool if the square is a mine
*/
bool Mine::isMine() const
{
	return isAMine;
}

/**
* Sets the adjacent number.
*
* @param number the new adjacent number
*/
void Mine::setAdjacentNumber( const int number )
{
	if( 0 <= number && number <= 8 ) 
		adjacentMines = number;
}

/**
* Returns the adjacent number.
*
* @return int the number of adjacent mines.
*/
int Mine::getAdjacentNumber() const
{
	return adjacentMines;
}

/**
 * Sweeps the mine.
 */
void Mine::sweep()
{
	if( !flagged )
		swept = true;
}

/**
 * Checks if the mine has been swept.
 *
 * @return bool the swept value.
 */
bool Mine::isSwept() const
{
	return swept;
}

/**
* Flags the mine.
*/
void Mine::flag()
{
	// One can only flag/unflag a non swept square
	if( !swept )
		flagged = !flagged;
}

/**
* Checks if the mine has been flagged.
*
* @return bool the flagged value.
*/
bool Mine::isFlagged() const
{
	return flagged;
}

/**
* Increases the adjacent number if not a mine by one.
*/
void Mine::incrementAdjacentNumber()
{
	++adjacentMines;
}

/**
* Resets the flags on the mine.
*/
void Mine::resetFlags()
{
	swept = false;
	flagged = false;
}

/**
* Resets the flags and states of the mine.
*/
void Mine::resetFlagsAndStates()
{
	resetFlags();
	setAdjacentNumber( 0 );
	setAsMine( false );
}
